package ar.edu.unicen.pladema.vc1.formats.sur;

import ar.edu.unicen.pladema.ui.model.g3d.Triangle;

public class TriangleReader implements IReader {
	private static final int VERTEX1=1;
	private static final int VERTEX2=2;
	private static final int VERTEX3=3;
	
	private int state;
	private Triangle triangle;
	
	public TriangleReader() {
		state = VERTEX1;
	}
	@Override
	public IReader readed(String token, Data3D data3d) {
		IReader response = DefaultReader.readers(token, this);
		if (response != null) {return response;}
		switch (state) {
			case VERTEX1: {
				triangle = new Triangle();
				triangle.setVertex1(token);
				state = VERTEX2;
				break;
			}
			case VERTEX2: {
				triangle.setVertex2(token);
				state = VERTEX3;
				break;
			}
			case VERTEX3: {
				triangle.setVertex3(token);
				state = VERTEX1;
				data3d.addTriangle(triangle);
				break;
			}
			default: {
				break;
			}
		}
		return this;
	}

}
